package net.yambal.android.secretary_alarm;

import java.util.List;

import net.yambal.android.geo.ArrayAdapterLocationLogItem;
import net.yambal.android.geo.db.LocationLogItem;
import net.yambal.android.geo.db.TableLocationLog;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class ActivityAboutKnownLocation extends Activity {
	private ListView _listviewLogs;
	private String _user_label;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_unknown_location_list);
        
        Intent intent = getIntent();
        _user_label = intent.getStringExtra("user_label");
        
        _listviewLogs = (ListView)findViewById(R.id.UnknownLocationListView);
        _listviewLogs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

				ListView list_view = (ListView)parent;
				LocationLogItem item = (LocationLogItem)list_view.getItemAtPosition(position);
				ActivityAboutKnownLocation.this.onItemClick(item);
				return;
			}
		});
    }
    
    private ProgressDialog progressDialog;
    private void onItemClick(LocationLogItem item){
    	
    	Intent unknown = new Intent(this, net.yambal.android.secretary_alarm.ActivityUnknownLocation.class);
    	unknown.putExtra("search_key", item.address);
		startActivity(unknown);
    }
    
	@Override
	public void onPause(){
		super.onPause();
		if(progressDialog != null){
			progressDialog.dismiss();
			progressDialog = null;
		}
	}
    
    @Override
    public void onResume(){
    	super.onResume();
    	
    	TableLocationLog table = TableLocationLog.getInstance(this);
    	List<LocationLogItem> items = table.getLogByLabel(_user_label);
    	if(items == null || items.size() == 0){
    		
    	}else{
	    	ArrayAdapterLocationLogItem _array_adapter = new ArrayAdapterLocationLogItem(this, R.layout.layout_livedoor_location_list_item, items, true);
	    	_listviewLogs.setAdapter(_array_adapter);
    	}
    }
}
